import java.sql.*;


    //所有Dao的父类
    public class BaseDao {
        protected Connection con;
        protected PreparedStatement ps;
        protected ResultSet rs;

        //建立连接
        public void setConnection() {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                this.con = DriverManager.getConnection("jdbc:mysql://localhost:23456/mydb2?characterEncoding=utf-8", "root", "lovo");


            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        //关闭连接
        public void closeConnection() {
            try {
                if (rs != null)
                    rs.close();
                if (ps != null)
                    ps.close();
                if (con != null)
                    con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

